package net.inxweb.bluemeerkat.domain.service.impl;

import java.util.List;

import javax.annotation.Resource;

import net.inxweb.bluemeerkat.domain.model.glossary.GlossaryInstance;
import net.inxweb.bluemeerkat.domain.model.glossary.GlossaryType;
import net.inxweb.bluemeerkat.domain.repository.GlossaryInstanceRepository;
import net.inxweb.bluemeerkat.domain.repository.GlossaryTypeRepository;
import net.inxweb.bluemeerkat.domain.service.GlossaryService;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("glossaryServiceImpl") 
@Transactional(readOnly = true) 
public class GlossaryServiceImpl implements GlossaryService { 
	@Resource(name="glossaryTypeRepositoryHibernate")
	private GlossaryTypeRepository glossaryTypeRepository;
	
	@Resource(name="glossaryInstanceRepositoryHibernate")
	private GlossaryInstanceRepository glossaryInstanceRepository;
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public Long createGlossaryInstance(GlossaryInstance glossaryInstance) { 
		return glossaryInstanceRepository.add(glossaryInstance);
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public Long createGlossaryType(GlossaryType glossaryType) {
		return glossaryTypeRepository.add(glossaryType);
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public void modifyGlossaryInstance(GlossaryInstance glossaryInstance) {
		glossaryInstanceRepository.modify(glossaryInstance);
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public void modifyGlossaryType(GlossaryType glossaryType) {
		glossaryTypeRepository.modify(glossaryType); 
	} 

	public List<GlossaryInstance> findAllGlossaryInstance() {
		return glossaryInstanceRepository.findAll();
	}

	public List<GlossaryType> findAllGlossaryType() { 
		return glossaryTypeRepository.findAll();
	}

	public GlossaryInstance findGlossaryInstance(Long id) {
		return glossaryInstanceRepository.find(id);
	}

	public GlossaryType findGlossaryType(Long id) { 
		return glossaryTypeRepository.find(id);
	}
}
